#include <bits/stdc++.h>
using namespace std;
int t;
int solve() {
    int n,a[200005],f[200005][2];

    for (int i = 0; i < n; i++) cin >> a[i];
    f[0][0] = f[0][1] = 0;
    for (int i = 1; i < n; i++) {
        f[i][0] = max(f[i-1][0] + (a[i] == a[i-1] ? a[i] : 0), f[i-1][1] + (a[i] == a[i-2] ? a[i] : 0));
        f[i][1] = max(f[i-1][1] + (a[i] == a[i-1] ? a[i] : 0), f[i-1][0] + (a[i] == a[i-2] ? a[i] : 0));
    }
    return max(f[n-1][0],f[n-1][1]);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",sdout);
    cin >> t;
    while (t--) cout << solve() << endl;
    return 0;
}
